﻿<%@ WebHandler Language="C#" Class="LevelCompetencyLoad" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using Assesment.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;
using Assesment.Library.Enum;
using Assesment.Web.Support;
using Newtonsoft.Json.Linq;

  public class LevelCompetencyLoad :  Assesment.Web.BaseHandler {

      LevelCompetencyRepo LevelCompetencyDal = new LevelCompetencyRepo(ConfigurationManager.ConnectionStrings["AssesmentConn"].ConnectionString);
        string MethodName = string.Empty;
        
        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);

            if (context.Request.Params["method"] != null)
                MethodName = context.Request.Params["method"];


            if (MethodName == "getlevelcomptid")
            {
                int comptID = Convert.ToInt32(context.Request.Params["comptID"].ToString());

                List<LevelCompetency> list = LevelCompetencyDal.GetListByCompetencyID(comptID);
                var result = list.OrderBy(x=>x.Level);
                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
            }

            if (MethodName == "getbyid")
            {
                int levelID = Convert.ToInt32(context.Request.Params["levelID"].ToString());
                List<LevelCompetency> list = LevelCompetencyDal.GetList();
                var result = list.Where(x=>x.ID==levelID);
                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
            }
            
            }

       
        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

